// 引入路由组件、
// import Home from '@/pages/Home/Home.vue'
import Login from '@/pages/Login/Login.vue'
import Search from '@/pages/Search/Search.vue'
import Register from '@/pages/Register/Register.vue'
import Detail from '@/pages/Detail/Detail.vue'
import ShopCartSuccess from '@/pages/AddCartSuccess/AddCartSuccess.vue'
import ShopCart from '@/pages/ShopCart/ShopCart.vue'
import Trade from '@/pages/Trade/Trade.vue'
import Pay from '@/pages/Pay/Pay.vue'
import PaySuccess from '@/pages/PaySuccess/PaySuccess.vue'
import Center from '@/pages/Center/Center.vue'
// 二级路由组件
import MyOrder from '@/pages/Center/myOrder/myOrder.vue'
import GroupOrder from '@/pages/Center/groupOrder/groupOrder.vue'
// 懒加载
// const foo = ()=>{
//     return import("@/pages/Home/Home.vue") 
// }


export default [
    {
        path: '/center',
        component: Center,
        meta: {show: true},
        children: [{
            path: 'myorder',
            component: MyOrder
        },
        {
                path: 'grouporder',
                component: GroupOrder
        },{
            path: '/center',
            redirect: '/center/myorder'
        }]
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
        meta: {show: true}
    },
    {
        path: '/pay/:orderId?',
        component: Pay,
        meta: {show: true},
        beforeEnter: (to, from, next)=>{
            if(from.path == '/trade' || from.path.indexOf('pay') != -1) {
                next()
            } else{
                next(false)
            }
        }
    },
    {
        path:'/trade',
        component: Trade,
        meta: {show: true},
        // 路由独享守卫
        beforeEnter: (to, from, next)=>{
            if(from.path =='/shopCart' || from.path =='/trade') {
                next() 
            } else {
                next(false)
            }
        }
    },
    {
        path: '/shopCart',
        component: ShopCart,
        meta:{show: false}
    },
    {
        path: '/addcartsuccess',
        name: 'addcartsuccess',
        component: ShopCartSuccess,
        meta:{show: true}
    },
    {
        path: '/home',
        // 路由懒加载
        component: ()=> import("@/pages/Home/Home.vue"),
        meta:{show: true}
    },
    {
        path: '/login',
        component: Login,
        meta:{show: false}
    },
    {
        path: '/search/:keyword?',
        component: Search,
        meta:{show: true},
        name: 'search',
        // 路由传递props数据
        // props: true
        // 
        // props: {a: 1, b:2}
        // 函数写法：可以params参数、query参数，通过props传递给路由组件
        props: ($route)=>{
            return {keyword: $route.params.keyword}
        }
    },
    {
        path: '/register',
        component: Register,
        meta:{show: false}
    },
    {
        path: '/detail/:skuid?',
        component: Detail,
        meta:{show: false}
    },
    // 重定向
    {
        path: '*',
        redirect: '/home'
    }
]